package getData;
import java.io.*;
//import java.io.FileReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.*;
import util.SysProperty;
public class getData {
	public Vector getDatafromFile(String filename)
	{
		Vector v=new Vector();
		try{
			BufferedReader in=new BufferedReader(new FileReader(filename));
			int i=0;
			while(in.read() !=-1){
				//System.out.println(in.readLine());
				String [] str= in.readLine().split(",");
				//System.out.println(str[0]+" "+str[1]);
				v.add(i,str);
				i++;
			}
			in.close();
		}catch (Exception e){
			System.out.println(e.toString());
		}
		return v;
	}

	public HashMap getHM()
	{
        HashMap hm = new HashMap();
        SysProperty sp = new SysProperty("filedata.ini");
        hm.put("db",sp.getProperty("db"));
        hm.put("path1",sp.getProperty("path1"));
        hm.put("path2",sp.getProperty("path2"));
        hm.put("path3",sp.getProperty("path3"));
        hm.put("sql",sp.getProperty("sql"));

        return hm;
	}
	

	public Vector getOracle10gData(String driver)
	{
		Vector v = new Vector();
	    try{

		  Class.forName(driver);
		  //Connection conn=DriverManager.getConnection((String)hm1.get("path1"),(String)hm1.get("path2"),(String)hm1.get("path3"));
		  Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@cmgcdb02:1521:cmctst","dbakm","kmdba");		  
	
     	  Statement s=conn.createStatement();
     	  String sql="select a.emp_no,a.emp_name, b.dept_name from cmc_employee a,cmc_department b where a.emp_unit=b.dept_no and trim(b.invalid_date) is null and trim(a.emp_leave_date)is null and a.dept_level1='A124' order by dept_name,emp_no";
		  ResultSet rs=s.executeQuery(sql);

          int numColumns = rs.getMetaData().getColumnCount();
          String[] columnName=new String[numColumns];
          for(int i=0;i<numColumns;i++)
        	  columnName[i]=rs.getMetaData().getColumnName(i+1);
          while(rs.next())
          {
             HashMap hm=new HashMap();
             for(int i=0;i<numColumns;i++)
            	 hm.put(rs.getMetaData().getColumnName(i+1),rs.getString(i+1));
             v.add(hm);
          }
    	  s.close();
    	  conn.close();
		  }catch(Exception e){System.out.println(e.toString());}
		return v;
	}
}
